##@package XmlCppClassGenerator.Interpretor
# Contains class wich allows to read an XML file and translate its
# content in a ClassRepresentation or StructureRepresentatation (from
# TypeDefinitions.py). It also contains a helper function which does
# upper- lowercase conversion.
#
# @author Johan "Solo" Luisier
# @date October 2011

from xml.dom import minidom
from TypeDefinitions import *
from Translator import *
from CodeReader import *
from XmlCppClassGenerator.OutputStreams import OutputStream

import subprocess
import os.path

## Function which replaces the first letter of a given string by its
# lowercase version.
#
# @param[in] string string which will be changed.
#
# @return the given string with its first letter put in lowercase.
def lowerFirstLetter( string ) :
    return string[0].lower() + string[1:]

## Class implementing the conversion of an XML file into
## ClassRepresentation objects.
#
#
# Inherits from OutputStream so that nice output can be used.
#
# @author Johan "Solo" Luisier
# @date October 2011
class Interpretor( OutputStream ) :
    ## Constructor
    # Initialises the data members to default (and empty) values. The
    # header and implementation files extentions are ".hpp" and ".cpp"
    # respectively.
    #
    # @param[in] self reference on calling instance.
    def __init__( self ) :
        OutputStream.__init__( self )
        ## XML description file that will be read.
        self.__XmlFileName = ""
        ## Document node of the XML file.
        self.__XmlDomDocument  = None
        ## List of representations built from the read XML file.
        self.__Representations = []
        ## Extention string for the header file names.
        self.__HeaderExtension = ".hpp"
        ## Extention string for the implementation file names.
        self.__ImplementationExtension = ".cpp"
        ## Instance of Translator, providing translated messages,
        # comments and simple words.
        self.__Translator = None
        ## Instance of CodeReader, providing method bodies.
        self.__CodeReader = CodeReader()
        ## Contains \e True or \e False for each representation, sets
        # the production of comments for the corresponding object.
        self.__FlagComment = []
    ## Allows to change the file name.
    #
    # @param[in] self reference on calling instance.
    # @param[in] fileName new value of XmlFileName.
    #
    # @return value of XmlFileName
    def setXmlFileName( self, fileName ) :
        self.__Representations = []
        self.__XmlFileName = fileName
        return self.__XmlFileName
    ## Allows to access the file name.
    #
    # @param[in] self reference on calling instance.
    #
    # @return the value of XmlFileName
    def getXmlFileName( self ) :
        return self.__XmlFileName
    ## Allows to change the header file extension.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] headerExt new value of HeaderExtension
    #
    # @return the value of HeaderExtension
    def setHeaderExtension( self, headerExt ) :
        self.__HeaderExtension = headerExt
        return self.__HeaderExtension
    ## Allows to get the value of HeaderExtension.
    #
    # @param[in] self reference on the calling instance.
    #
    # @return the value of HeaderExtension
    def getHeaderExtension( self ) :
        return self.__HeaderExtension
    ## Allows to change the implementation file extension.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] implementationExt new value of ImplementationExtension
    #
    # @return the value of ImplementationExtension
    def setImplementationExtension( self, implementationExt ) :
        self.__ImplementationExtension = implementationExt
        return self.__ImplementationExtension
    ## Allows to get the value of ImplementationExtension.
    #
    # @param[in] self reference on the calling instance.
    #
    # @return the value of ImplementationExtension
    def getImplementationExtension( self ) :
        return self.__ImplementationExtension
    ## Allows to get the translation file read. This translation file
    # provides the bodies and comments of the getters / setters, and
    # the empty body for other methods.  
    #
    # Can terminate the execution if the file is corrupted, not
    # present, if neither the wanted language nor english can be
    # found.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] trans wanted language.
    def setTranslator( self, trans ) :
        self.__Translator = trans
    ## Allows to parse the (once the file name has bee set).
    #
    # @param[in] self reference on calling instance.
    #
    # @return 1 if the document does not have "classes" as the root
    # node, 0 if it does.
    def loadDomTree( self ) :
        self.__XmlDomDocument = minidom.parse( self.__XmlFileName )
        ## Root element node of the XML file.
        self.__XmlDomRoot = self.__XmlDomDocument.documentElement
        if ( self.__XmlDomRoot.nodeName != "classes" ) :
            message = \
                self.__Translator.getInformationMessage( "rootElementError" )[0]
            self.fatal( message.format( "classes" ) )
            return 1
        return 0
    ## Reads through the whole DOM tree and looks for the "class" DOM
    # element. For each of these, the construction of the
    # ClassRepresentation is delegated to the readAndLoadClass method.
    #
    # @param[in] self reference on calling instance.
    #
    # @return 0 if everything went fine and smoothly, or the error
    # code.
    def findObjects( self ) :
        retVal = 0
        for child in self.__XmlDomRoot.childNodes :
            if ( child.nodeName == "class" ) :
                message = \
                    self.__Translator.getInformationMessage( "objectFound" )[0]
                what = self.__Translator.getInformationString( "class" )[0]
                self.debug( message.format( what ) )
                retVal = self.readAndLoadObject( child )
            elif ( child.nodeName == "struct" ) :
                message = \
                    self.__Translator.getInformationMessage( "objectFound" )[0]
                what = self.__Translator.getInformationString( "struct" )[0]
                self.debug( message.format( what ) )
                retVal = self.readAndLoadObject( child )
        return retVal
    ## Returns a %ClassRepresentation or a %StructureRepresentation
    # object depending on the objct type (i.e. "class" or "struct").
    # This is used since the method actually creating the object is
    # the same, but the object has to be created correctly before
    # adding constructors, methods, members, ...
    #
    # @param[in] self reference on calling instance.
    # @param[in] what the "class" or "struct" string.
    #
    # @return an instance of %ClassRepresentation or
    # %StructureRepresentation.
    def _buildObject( self, what ) :
        if ( what == "class" ) :
            return ClassRepresentation()
        elif ( what == "struct" ) :
            return StructureRepresentation()
        else :
            return None
    ## Creates a %ClassRepresentation or a %StructureRepresentation
    # object from the corresponding element node.
    # The children are read by dedicated functions. Once created, the
    # object is added to the __Representations array.
    #
    # @param[in] self reference on calling instance.
    # @param[in] node instance of node which node name is "class".
    #
    # @return the number of loaded object(s).
    def readAndLoadObject( self, node ) :
        back = self._buildObject( node.nodeName )

        if ( back == None ) :
            message = \
             self.__Translator.getInformationMessage( "unknownObjectType" )[ 0 ]
            self.error( message.format( node.nodeName ) )
            return len( self.__Representations )

        commentFlag = True

        for child in node.childNodes :
            if ( child.nodeName == "name" ) :
                back.setObjectName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "namespace" ) :
                back.setNamespace( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "author" ) :
                back.addAuthor( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "date" ) :
                back.setDate( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "inherits" ) :
                fileStr = ""
                accType = "public"
                virtualStr = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "parent" ) :
                        fileStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "access" ) :
                        accType = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "virtual" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            virtualStr = "virtual"

                back.addInherits( fileStr, accType, virtualStr )
            elif ( child.nodeName == "globalTypedef" ) :
                back.addGlobalTypedef( self.readTypedef( child ) )
            elif ( child.nodeName == "globalEnum" ) :
                back.addGlobalEnum( self.readEnum( child ) )
            elif ( child.nodeName == "forwardDeclaration" ) :
                back.addForwardDeclaration( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "include" ) :
                local = False
                header = False
                includeFile = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "file" ) :
                        includeFile = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "local" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ):
                            local = True
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            header = True
                            
                if ( header ) :
                    back.addHeaderInclude( includeFile, local )
                else :
                    back.addImplementationInclude( includeFile, local )

            elif ( child.nodeName == "usedNamespace" ) :
                namespaceStr = ""
                header = False
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "namespace" ) :
                        namespaceStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true"    ) :
                            header = True
                back.addUsingNamespace( namespaceStr, header )

            elif ( child.nodeName == "comments" ) :
                if ( child.hasChildNodes and \
                         child.firstChild.nodeValue.strip() == "false" ) :
                    commentFlag == False
            elif ( child.nodeName == "template" ) :
                keyword = ""
                param   = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "identifier" ) :
                        param = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "keyword" ) :
                        keyword = grandChild.firstChild.nodeValue.strip()
                back.addTemplateParameter( keyword, param )
            elif ( child.nodeName == "public" or \
                   child.nodeName == "protected" or \
                   child.nodeName == "private" or \
                   child.nodeName == "signals" ) :
                self.loopOnObjectItems( back, child, child.nodeName )

        for constructor in back.getPublicConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getProtectedConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getPrivateConstructors() :
            self.addConstructorBody( back, constructor )

        destructorAdded = False

        for ( what, access ) in back.getAutomaticMethods().iteritems() :
            if ( what == "copyConstructor" ) :
                self.addCopyConstructor( back, access )
            elif ( what == "affectationOperator" ) :
                self.addAffectationOperator( back, access )
            elif ( what == "comparisonOperator" ) :
                self.addComparisonOperator( back, access )
            elif ( what == "destructor" ) :
                self.addDestructor( back, access )
                destructorAdded = True

        if ( back.getObjectType() == "class" and not destructorAdded ) :
            self.addDestructor( back )
        
        self.__Representations.append( back )
        self.__FlagComment.append( commentFlag )

        return len( self.__Representations )
    ## Creates a %ClassRepresentation object from a "&lt;class&gt;"
    # element node. The children are read by dedicated functions. Once
    # created, the object is added to the __Representations array.
    #
    # @param[in] self reference on calling instance.
    # @param[in] node instance of node which node name is "class".
    #
    # @return the number of loaded class(es).
    def readAndLoadClass( self, node ) :
        back = ClassRepresentation()

        commentFlag = True

        for child in node.childNodes :
            if ( child.nodeName == "name" ) :
                back.setObjectName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "namespace" ) :
                back.setNamespace( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "author" ) :
                back.addAuthor( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "date" ) :
                back.setDate( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "inherits" ) :
                fileStr = ""
                accType = "public"
                virtualStr = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "parent" ) :
                        fileStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "access" ) :
                        accType = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "virtual" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            virtualStr = "virtual"

                back.addInherits( fileStr, accType, virtualStr )
            elif ( child.nodeName == "globalTypedef" ) :
                back.addGlobalTypedef( self.readTypedef( child ) )
            elif ( child.nodeName == "globalEnum" ) :
                back.addGlobalEnum( self.readEnum( child ) )
            elif ( child.nodeName == "forwardDeclaration" ) :
                back.addForwardDeclaration( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "include" ) :
                local = False
                header = False
                includeFile = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "file" ) :
                        includeFile = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "local" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ):
                            local = True
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            header = True
                            
                if ( header ) :
                    back.addHeaderInclude( includeFile, local )
                else :
                    back.addImplementationInclude( includeFile, local )

            elif ( child.nodeName == "usedNamespace" ) :
                namespaceStr = ""
                header = False
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "namespace" ) :
                        namespaceStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true"    ) :
                            header = True
                back.addUsingNamespace( namespaceStr, header )

            elif ( child.nodeName == "comments" ) :
                if ( child.hasChildNodes and \
                         child.firstChild.nodeValue.strip() == "false" ) :
                    commentFlag == False
            elif ( child.nodeName == "template" ) :
                keyword = ""
                param   = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "identifier" ) :
                        param = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "keyword" ) :
                        keyword = grandChild.firstChild.nodeValue.strip()
                back.addTemplateParameter( keyword, param )
            elif ( child.nodeName == "public" or \
                   child.nodeName == "protected" or \
                   child.nodeName == "private" or \
                   child.nodeName == "signals" ) :
                self.loopOnObjectItems( back, child, child.nodeName )

        for constructor in back.getPublicConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getProtectedConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getPrivateConstructors() :
            self.addConstructorBody( back, constructor )

        destructorAdded = False

        for ( what, access ) in back.getAutomaticMethods().iteritems() :
            if ( what == "copyConstructor" ) :
                self.addCopyConstructor( back, access )
            elif ( what == "affectationOperator" ) :
                self.addAffectationOperator( back, access )
            elif ( what == "comparisonOperator" ) :
                self.addComparisonOperator( back, access )
            elif ( what == "destructor" ) :
                self.addDestructor( back, access )
                destructorAdded = True

        if ( back.getObjectType() == "class" and not destructorAdded ) :
            self.addDestructor( back )
        
        self.__Representations.append( back )
        self.__FlagComment.append( commentFlag )

        return len( self.__Representations )
    ## Creates a StructureRepresentation object from a "&lt;struct&gt;"
    # element node. The children are read by dedicated functions. Once
    # created, the object is added to the __Representations array.
    #
    # @param[in] self reference on calling instance.
    # @param[in] node instance of node which node name is "struct".
    #
    # @return the number of loaded class(es).
    def readAndLoadStructure( self, node ) :
        back = StructureRepresentation()

        commentFlag = True

        for child in node.childNodes :
            if ( child.nodeName == "name" ) :
                back.setObjectName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "namespace" ) :
                back.setNamespace( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "author" ) :
                back.addAuthor( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "date" ) :
                back.setDate( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "inherits" ) :
                fileStr = ""
                accType = "public"
                virtualStr = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "parent" ) :
                        fileStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "access" ) :
                        accType = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "virtual" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                             == "true" ) :
                                virtualStr = "virtual"
                 
                back.addInherits( fileStr, accType, virtualStr )
            elif ( child.nodeName == "globalTypedef" ) :
                back.addGlobalTypedef( self.readTypedef( child ) )
            elif ( child.nodeName == "globalEnum" ) :
                back.addGlobalEnum( self.readEnum( child ) )
            elif ( child.nodeName == "forwardDeclaration" ) :
                back.addForwardDeclaration( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "include" ) :
                local = False
                header = False
                includeFile = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "file" ) :
                        includeFile = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "local" ) :
                        if ( not ( grandChild.hasChildNodes() and \
                                   grandChild.firstChild.nodeValue.strip() \
                                   == "false" ) ) :
                            local = True
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not ( grandChild.hasChildNodes() and \
                                   grandChild.firstChild.nodeValue.strip() \
                                   == "false" ) ) :
                            header = True
                            
                if ( header ) :
                    back.addHeaderInclude( includeFile, local )
                else :
                    back.addImplementationInclude( includeFile, local )

            elif ( child.nodeName == "usedNamespace" ) :
                namespaceStr = ""
                header = False
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "namespace" ) :
                        namespaceStr = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "header" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true"    ) :
                            header = True
                back.addUsingNamespace( namespaceStr, header )

            elif ( child.nodeName == "comments" ) :
                if ( child.firstChild.nodeValue.strip() == "false" ) :
                    commentFlag == False
            elif ( child.nodeName == "template" ) :
                keyword = ""
                param   = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "identifier" ) :
                        param = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "keyword" ) :
                        keyword = grandChild.firstChild.nodeValue.strip()
                back.addTemplateParameter( keyword, param )
            elif ( child.nodeName == "public" or \
                   child.nodeName == "protected" or \
                   child.nodeName == "private" or \
                   child.nodeName == "signals" ) :
                self.loopOnObjectItems( back, child, child.nodeName )

        for constructor in back.getPublicConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getProtectedConstructors() :
            self.addConstructorBody( back, constructor )
        for constructor in back.getPrivateConstructors() :
            self.addConstructorBody( back, constructor )

        for ( what, access ) in back.getAutomaticMethods().iteritems() :
            if ( what == "copyConstructor" ) :
                self.addCopyConstructor( back, access )
            elif ( what == "affectationOperator" ) :
                self.addAffectationOperator( back, access )
            elif ( what == "comparisonOperator" ) :
                self.addComparisonOperator( back, access )

        if ( destructorPresent ) :
            self.addDestructor( back )
        
        self.__Representations.append( back )
        self.__FlagComment.append( commentFlag )

        return len( self.__Representations )
    ## Loops on element nodes children of "public", "protected" or
    # "private" node, and calls the appropriate function to interpret
    # the found nodes.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "public", "protected" or
    # "private").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def loopOnObjectItems( self, representation, node, access ) :
        for child in node.childNodes :
            if ( child.nodeName == "constructor" ) :
               self.addConstructor( representation, child, access )
            elif ( child.nodeName == "destructor" ) :
                self.addSpecialMethod( representation, "destructor", \
                                           access )
            elif ( child.nodeName == "typedef" ) :
                self.addTypedef( representation, child, access )
            elif ( child.nodeName == "enum" ) :
                self.addEnum( representation, child, access )
            elif ( child.nodeName == "copyConstructor" or \
                   child.nodeName == "affectationOperator" or \
                   child.nodeName == "comparisonOperator" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    self.addSpecialMethod( representation, child.nodeName, \
                                               access )
            elif ( child.nodeName == "method" ) :
               self.addMethod( representation, child, access )
            elif ( child.nodeName == "slot" ) :
                self.addSlot( representation, child, access )
            elif ( child.nodeName == "member" ) :
               self.addMember( representation, child, access )
            elif ( child.nodeName == "signal" ) :
                self.addSignal( representation, child, access )
    ## Adds a special method
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] what name of the item which will be added.
    # @param[in] access access specifier of the item.
    def addSpecialMethod( self, representation, what, access ) :
        methodName = self.__Translator.getInformationString( what )[0]
        if ( not representation.addAutomaticMethod( what, access ) ) :
            message = \
                self.__Translator.getInformationMessage( "alreadyPresent" )[0]
            self.warning( message.format( methodName, \
                                              representation.getObjectName() ) )
            return
        message = self.__Translator.getInformationMessage( "genMethod" )[0]
        self.verbose( message.format( access, methodName, \
                                          representation.getObjectName() ) )
    ## Adds a typedef to the given object representation.
    #
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "typedef").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addTypedef( self, representation, node, access ) :
        newTypedef = readTypedef( node )

        if ( access == "public" ) :
            retVal = representation.addPublicTypedef( newTypedef )
        elif ( access == "protected" ) :
            retVal = representation.addPublicTypedef( newTypedef )
        elif ( access == "private" ) :
            retVal = representation.addPublicTypedef( newTypedef )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addTypedef", access ) )
    ## Adds a enum to the given object representation.
    #
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "enum").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addEnum( self, representation, node, access ) :
        newEnum = self.readEnum( node )

        if ( access == "public" ) :
            retVal = representation.addPublicEnum( newEnum )
        elif ( access == "protected" ) :
            retVal = representation.addPublicEnum( newEnum )
        elif ( access == "private" ) :
            retVal = representation.addPublicEnum( newEnum )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addEnum", access ) )
    ## Adds a constructor to the given %ClassRepresentation.
    # The needed information is read and an instance of
    # %ConstructorRepresentation is built then added to the correct
    # container, depending on the access type.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "constructor").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addConstructor( self, representation, node, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "constructor" )[0]
        self.verbose( message.format( access, what ) )
        newConstructor = ConstructorRepresentation()
        newConstructor.setName( representation.getObjectName() )
        for child in node.childNodes :
            if ( child.nodeName == "template" ) :
                keyword = ""
                param   = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "identifier" ) :
                        param = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "keyword" ) :
                        keyword = grandChild.firstChild.nodeValue.strip()
                newMethod.addTemplateParameter( keyword, param )
            elif ( child.nodeName == "argument" ) :
                newConstructor.addArgument( self.readArgument( child ) )
            elif ( child.nodeName == "throw" ) :
                newConstructor.addThrownException( child.firstChild.nodeValue.strip() )
        
        comments = newConstructor.produceComment()
        message = self.__Translator.getInformationString( "constructor" )[0]
        comments = comments.format( message.capitalize() )
        newConstructor.setComments( comments )

        retVal = 0

        if ( access == "public" ) :
            retVal = representation.addPublicConstructor( newConstructor )
        elif ( access == "protected" ) :
            retVal = representation.addProtectedConstructor( newConstructor )
        elif ( access == "private" ) :
            retVal = representation.addPrivateConstructor( newConstructor )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addConstructor", access ) )
    ## Adds the body to the constructors, once the %ClassRepresentation
    # is fully initialised.
    #
    # A body is added to the constructor. This body contains the 
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] constructor instance of constructor to be processed.
    def addConstructorBody( self, representation, constructor ) :
        if ( constructor.getBody() != "" ) : return
        body = str()
        if ( len( representation.getInherits() ) > 0 ) :
            body = " : "
            for array in representation.getInherits() :
                body += array[ 0 ] + "( ),\n"

        if ( representation.getNbrNonStaticMembers() > 0 ) :
            if ( body == "" ) : body = " : "
            body += "{}( ),\n" * representation.getNbrNonStaticMembers()
            body = body[:-2]
            body += "\n"
            body = body.format( *representation.getNonStaticMembers() )
            body += self.__CodeReader.getInformationBody( "empty" )[0]
            body = body.replace( "\\n", "\n" )
            constructor.setBody( body )
        else :
            if ( len( representation.getInherits() ) > 0 ) :
                body = body[:-2]
                body += "\n"
            body += self.__CodeReader.getInformationBody( "empty" )[0]
            body = body.replace( "\\n", "\n" )
            constructor.setBody( body )
    ## Adds a copy constructor.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addCopyConstructor( self, representation, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "copyConstructor" )[0]
        self.verbose( message.format( access, what ) )
        copyConstructor = ConstructorRepresentation()
        copyConstructor.setName( representation.getObjectName() )
        newArgument = ArgumentRepresentation()
        newArgument.setTypeName( representation.getObjectName() )
        newArgument.setReference( True )
        newArgument.setConstness( True )
        newArgument.setName( lowerFirstLetter( representation.getObjectName() ) )
        copyConstructor.addArgument( newArgument )

        comment = copyConstructor.produceComment()
        comment = comment.format( what.capitalize() )
        copyConstructor.setComments( comment )

        argName = newArgument.getName()

        body = str()
        if ( len( representation.getInherits() ) > 0 ) :
            body = " : "
            for array in representation.getInherits() :
                body += array[ 0 ] + "( {0} ),\n".format( argName )
        if ( representation.getNbrNonStaticMembers() > 0 ) :
            if ( body == "" ) : body = " : "
            body += "{}( ),\n" * representation.getNbrNonStaticMembers()
            body = body[:-2]
            body += "\n"
            memberList = representation.getNonStaticMembers()
            body = body.format( *memberList )
            body = body.replace( "( )", "( {} )" )
            memberList = [ argName + "." + lowerFirstLetter( obj ) + "()" for obj in memberList ]
            body = body.format( *memberList )
            body += self.__CodeReader.getInformationBody( "empty" )[0]
            body = body.replace( "\\n", "\n" )
            copyConstructor.setBody( body )
        else :
            if ( body != "" ) :
                body = body[:-2] + "\n"
            body += self.__CodeReader.getInformationBody( "empty" )[0]
            body = body.replace( "\\n", "\n" )
            copyConstructor.setBody( body )
        
        if ( access == "public" ) :
            representation.addPublicConstructor( copyConstructor )
        elif ( access == "protected" ) :
            representation.addProtectedConstructor( copyConstructor )
        elif ( access == "private" ) :
            representation.addPrivateConstructor( copyConstructor )
    ## Adds an affectation operator.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addAffectationOperator( self, representation, access ) :
        what = \
            self.__Translator.getInformationString( "affectationOperator" )[ 0 ]
        message = self.__Translator.getInformationMessage( "addItem" )[ 0 ]
        self.verbose( message.format( access, what ) )
        affectation = MethodRepresentation()
        affectation.setName( "operator=" )
        newArgument = ArgumentRepresentation()
        newArgument.setTypeName( representation.getObjectName() )
        newArgument.setReference( True )
        newArgument.setConstness( True )
        newArgument.setName( lowerFirstLetter( representation.getObjectName() ) )
        affectation.addArgument( newArgument )
        affectation.setTypeName( representation.getObjectName() )
        affectation.setReference( True )

        argName = newArgument.getName()

        body = "{\n"
        if ( len( representation.getInherits() ) > 0 ) :
            for array in representation.getInherits() :
                body += "this -> " + array[ 0 ] + "::operator=( {0} );\n".format( argName )
        if ( representation.getNbrNonStaticMembers() > 0 ) :
            rawLine = "{0} = {1}.{2}();\n"
            for member in representation.getNonStaticMembers() :
                body += rawLine.format( member, argName, lowerFirstLetter( member ) )
        body += "return *this;\n"
        body += "}\n"
        affectation.setBody( body )

        if ( access == "public" ) :
            representation.addPublicMethod( affectation )
        elif ( access == "protected" ) :
            representation.addProtectedMethod( affectation )
        elif ( access == "private" ) :
            representation.addPrivateMethod( affectation )
    ## Adds a comparison operator.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addComparisonOperator( self, representation, access ) :
        what = \
            self.__Translator.getInformationString( "comparisonOperator" )[ 0 ]
        message = self.__Translator.getInformationMessage( "addItem" )[ 0 ]
        self.verbose( message.format( access, what ) )
        comparison = MethodRepresentation()
        comparison.setName( "operator==" )
        newArgument = ArgumentRepresentation()
        newArgument.setTypeName( representation.getObjectName() )
        newArgument.setReference( True )
        newArgument.setConstness( True )
        newArgument.setName( lowerFirstLetter( representation.getObjectName() ) )
        comparison.addArgument( newArgument )
        comparison.setTypeName( "bool" )
        comparison.setReference( False )
        comparison.setFunctionConstness( True )

        argName = newArgument.getName()

        body = "{\n"
        if ( len( representation.getInherits() ) > 0 ) :
            rawLine = "if ( ! this -> {0}::operator==( {1} ) )\n return false;\n"
            for array in representation.getInherits() :
                body += rawLine.format( array[0], argName )
        body += "if ( "
        if ( representation.getNbrNonStaticMembers() > 0 ) :
            rawLine = "{0} == {1}.{2}() &&\n"
            for member in representation.getNonStaticMembers() :
                body += rawLine.format( member, argName, lowerFirstLetter( member ) )
        body = body[:-3]
        body += ")\n return true;\n"
        body += "return false;\n"
        body += "}\n"
        comparison.setBody( body )

        if ( access == "public" ) :
            representation.addPublicMethod( comparison )
        elif ( access == "protected" ) :
            representation.addProtectedMethod( comparison )
        elif ( access == "private" ) :
            representation.addPrivateMethod( comparison )
    ## Adds a destructor to the given %ClassRepresentation.
    # The name is constructed from the class name, the body and the
    # comments are retrieved from the __CodeReader and __Translator
    # objects.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which a (public) destructor will be added.
    # @param[in] access access type for the destructor.
    def addDestructor( self, representation, access = "public" ) :
        destructor = ConstructorRepresentation()
        destructor.setName( "~" + representation.getObjectName() )
        destructor.setBody( self.__CodeReader.getInformationBody( "empty" )[0].replace( "\\n", "\n" ) )
        comments = destructor.produceComment()
        destructor.setVirtual( True )
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "destructor" )[0]
        self.verbose( message.format( access, what ) )
        comments = comments.format( what.capitalize() )
        destructor.setComments( comments )

        if ( access == "public" ) :
            representation.addPublicConstructor( destructor )
        elif ( access == "protected" ) :
            representation.addProtectedConstructor( destructor )
        elif ( access == "private" ) :
            representation.addPrivateConstructor( destructor )
    ## Allows to build a method-like object, this can be a method, a
    # slot or a signal.
    # The provided information for a method, a slot or a signal are
    # exactly the same, therefore a common way to read it is more than
    # reasonnable. This generic method does the information gathering
    # and returns awell-formed %MethodRepresentation object.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] node instance of node (i.e. "method", "slot" or
    # "signal").
    #
    # @return a %MethodRepresentation built from the retrieved
    # information.
    def _buildMethod( self, node ) :
        newMethod = MethodRepresentation()
        body = self.__CodeReader.getInformationBody( "empty" )[0]
        body = body.replace( "\\n", "\n" )
        newMethod.setBody( body )
        for child in node.childNodes :
            if ( child.nodeName == "template" ) :
                keyword = ""
                param   = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "identifier" ) :
                        param = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "keyword" ) :
                        keyword = grandChild.firstChild.nodeValue.strip()
                newMethod.addTemplateParameter( keyword, param )
            elif ( child.nodeName == "return" ) :
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "type" ) :
                        newMethod.setTypeName( grandChild.firstChild.nodeValue.strip () )
                    elif ( grandChild.nodeName == "const" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            newMethod.setConstness( True )
                    elif ( grandChild.nodeName == "ref" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            newMethod.setReference( True )
                    elif ( grandChild.nodeName == "ptr" ) :
                        if ( not grandChild.hasChildNodes() or \
                             grandChild.firstChild.nodeValue.strip() \
                                 == "true" ) :
                            newMethod.setPointer( True )
            elif ( child.nodeName == "name" ) :
                newMethod.setName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "argument" ) :
                newMethod.addArgument( self.readArgument( child ) )
            elif ( child.nodeName == "const" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMethod.setFunctionConstness( True )
            elif ( child.nodeName == "throw" ) :
                newMethod.addThrownException( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "static" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMethod.setStatic( True )
            elif ( child.nodeName == "virtual" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMethod.setVirtual( True )
            elif ( child.nodeName == "pureVirtual" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMethod.setPureVirtual( True )
            elif ( child.nodeName == "friend" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMethod.setFriend( True )

        return newMethod
    ## Adds a method to the given %ClassRepresentation.
    # The needed information is read and an instance of
    # %MethodRepresentation is built then added to the correct
    # container, depending on the access type.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "method").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addMethod( self, representation, node, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "method" )[0]
        self.verbose( message.format( access, what ) )
        newMethod = self._buildMethod( node )

        retVal = 0

        if ( access == "public" ) :
            retVal = representation.addPublicMethod( newMethod )
        elif ( access == "protected" ) :
            retVal = representation.addProtectedMethod( newMethod )
        elif ( access == "private" ) :
            retVal = representation.addPrivateMethod( newMethod )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addMethod", access ) )
    ## Adds a slot to the given %ClassRepresentation.
    # The needed information is read and an instance of
    # %MethodRepresentation is built then added to the correct
    # container, depending on the access type.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "slot").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addSlot( self, representation, node, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "method" )[0]
        self.verbose( message.format( access, "slot" ) )
        newMethod = self._buildMethod( node )

        retVal = 0

        if ( access == "public" ) :
            retVal = representation.addPublicSlot( newMethod )
        elif ( access == "protected" ) :
            retVal = representation.addProtectedSlot( newMethod )
        elif ( access == "private" ) :
            retVal = representation.addPrivateSlot( newMethod )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addSlot", access ) )
    ## Adds a signal to the given %ClassRepresentation.
    # The needed information is read and an instance of
    # %MethodRepresentation is built then added to the correct
    # container, depending on the access type.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "signal").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").
    def addSignal( self, representation, node, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "method" )[0]
        self.verbose( message.format( "private", "signal" ) )
        newMethod = self._buildMethod( node )

        retVal = representation.addSignal( newMethod )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addSignal", access ) )
    ## Adds a member to the given %ClassRepresentation.
    # The needed information is read and an instance of
    # %MemberRepresentation is built then added to the correct
    # container, depending on the access type.
    #
    # If the std / ptr getter or setter is enabled, the corresponding
    # method(s) are added to the public method container.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] representation instance of ClassRepresentation to
    # which the found item will be added.
    # @param[in] node instance of node (i.e. "member").
    # @param[in] access access specifier (i.e. "public", "protected" or
    # "private").    
    def addMember( self, representation, node, access ) :
        message = self.__Translator.getInformationMessage( "addItem" )[0]
        what = self.__Translator.getInformationString( "member" )[0]
        self.verbose( message.format( access, what ) )
        newMember = MemberRepresentation()
        for child in node.childNodes :
            if ( child.nodeName == "name" ) :
                newMember.setName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "type" ) :
                newMember.setTypeName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "const" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setConstness( True )
            elif ( child.nodeName == "ref" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setReference = True
            elif ( child.nodeName == "ptr" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setPointer( True )
            elif ( child.nodeName == "static" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setStatic( True )
            elif ( child.nodeName == "value" ) :
                newMember.setValue( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "mutable" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setMutable( True )
            elif ( child.nodeName == "stdGet" ) :
                if ( child.hasChildNodes() and \
                     child.firstChild.nodeValue.strip() == "false" ) :
                    newMember.setStdGet( False )
            elif ( child.nodeName == "stdSet" ) :
                if ( child.hasChildNodes() and \
                     child.firstChild.nodeValue.strip() == "false" ) :
                    newMember.setStdSet( False )
            elif ( child.nodeName == "ptrGet" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setPtrGet( True )
            elif ( child.nodeName == "ptrSet" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setPtrSet( True )
            elif ( child.nodeName == "refGet" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newMember.setRefGet( True )

        if ( newMember.getConstness() ) :
            newMember.setStdSet( False )
            newMember.setPtrSet( False )

        if ( newMember.getStdGet() == True ) :
            message = self.__Translator.getInformationMessage( "genMethod" )[0]
            what = self.__Translator.getInformationString( "getter" )[0]
            self.verbose( message.format( "std", what, newMember.getName() ) )
            newMethodStdGet = MethodRepresentation()
            newMethodStdGet.setTypeName( newMember.getTypeName() )
            newMethodStdGet.setReference( True )
            newMethodStdGet.setConstness( True )
            newMethodStdGet.setFunctionConstness( True )
            newMethodStdGet.setName( lowerFirstLetter( newMember.getName() ) )
            string = self.__CodeReader.getInformationBody( "stdGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodStdGet.setBody( "{\n " + string + "\n}\n" )
            string = self.__Translator.getInformationComment( "stdGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodStdGet.setComments( string )
            representation.addPublicMethod( newMethodStdGet )
        if ( newMember.getStdSet() == True ) :
            message = self.__Translator.getInformationMessage( "genMethod" )[0]
            what = self.__Translator.getInformationString( "setter" )[0]
            self.verbose( message.format( "std", what, newMember.getName() ) )
            newMethodStdSet = MethodRepresentation()
            newMethodStdSet.setTypeName( "void" )
            newMethodStdSet.setName( "set" + newMember.getName() )
            string = self.__CodeReader.getInformationBody( "stdSetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName(), lowerFirstLetter( newMember.getName() ) )
            newMethodStdSet.setBody( "{\n " + string + "\n}\n" )
            string = self.__Translator.getInformationComment( "stdSetter" )[0]
            string = string.format( newMember.getName(), lowerFirstLetter( newMember.getName() ) )
            string = string.replace( "\\n", "\n" )
            newMethodStdSet.setComments( string )
            newArgument = ArgumentRepresentation()
            newArgument.setTypeName( newMember.getTypeName() )
            newArgument.setReference( True )
            newArgument.setConstness( True )
            newArgument.setName( lowerFirstLetter( newMember.getName() ) )
            newMethodStdSet.addArgument( newArgument )
            representation.addPublicMethod( newMethodStdSet )
        if ( newMember.getPtrGet() == True ) :
            message = self.__Translator.getInformationMessage( "genMethod" )[0]
            what = self.__Translator.getInformationString( "getter" )[0]
            self.verbose( message.format( "ptr", what, newMember.getName() ) )
            newMethodPtrGet = MethodRepresentation()
            newMethodPtrGet.setTypeName( newMember.getTypeName() )
            string = self.__CodeReader.getInformationBody( "ptrGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodPtrGet.setBody( "{\n " + string + "\n}\n" )
            string = self.__Translator.getInformationComment( "ptrGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodPtrGet.setComments( string )
            newMethodPtrGet.setPointer( True )
            newMethodPtrGet.setConstness( True )
            newMethodPtrGet.setFunctionConstness( True )
            newMethodPtrGet.setName( lowerFirstLetter( newMember.getName() ) + "Ptr" )
            representation.addPublicMethod( newMethodPtrGet )
        if ( newMember.getPtrSet() == True ) :
            message = self.__Translator.getInformationMessage( "genMethod" )[0]
            what = self.__Translator.getInformationString( "setter" )[0]
            self.verbose( message.format( "ptr", what, newMember.getName() ) )
            newMethodPtrSet = MethodRepresentation()
            newMethodPtrSet.setTypeName( "void" )
            newMethodPtrSet.setName( "set" + newMember.getName() + "Ptr" )
            string = self.__CodeReader.getInformationBody( "ptrSetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName(), lowerFirstLetter( newMember.getName() ) )
            newMethodPtrSet.setBody( "{\n " + string + "\n}\n" )
            string = self.__Translator.getInformationComment( "ptrSetter" )[0]
            string = string.format( newMember.getName(), lowerFirstLetter( newMember.getName() ) )
            string = string.replace( "\\n", "\n" )
            newMethodPtrSet.setComments( string )
            newArgument = ArgumentRepresentation()
            newArgument.setTypeName( newMember.getTypeName() )
            newArgument.setPointer( True )
            newArgument.setName( lowerFirstLetter( newMember.getName() ) )
            newMethodPtrSet.addArgument( newArgument )
            representation.addPublicMethod( newMethodPtrSet )
        if ( newMember.getRefGet() == True ) :
            message = self.__Translator.getInformationMessage( "genMethod" )[0]
            what = self.__Translator.getInformationString( "refGetter" )[0]
            self.verbose( message.format( "ref", what, newMember.getName() ) )
            newMethodRefGet = MethodRepresentation()
            newMethodRefGet.setTypeName( newMember.getTypeName() )
            newMethodRefGet.setReference( True )
            newMethodRefGet.setName( "r" + newMember.getName() )
            string = self.__CodeReader.getInformationBody( "stdGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodRefGet.setBody( "{\n " + string + "\n}\n" )
            string = self.__Translator.getInformationComment( "refGetter" )[0]
            string = string.replace( "\\n", "\n" )
            string = string.format( newMember.getName() )
            newMethodRefGet.setComments( string )
            representation.addPublicMethod( newMethodRefGet )

        retVal = 0

        if ( access == "public" ) :
            retVal = representation.addPublicMember( newMember )
        elif ( access == "protected" ) :
            retVal = representation.addProtectedMember( newMember )
        elif ( access == "private" ) :
            retVal = representation.addPrivateMember( newMember )

        if ( retVal < 0 ) :
            message = \
                self.__Translator.getInformationMessage( "undefAccess" )[0]
            self.error( message.format( "_addMember", access ) )
    ## Reads an argument (of a method or constructor).
    #
    # @param[in] self reference on the calling instance.
    # @param[in] node instance of "argument" node.
    #
    # @return a new instance of %ArgumentRepresentation.
    def readArgument( self, node ) :
        newArgument = ArgumentRepresentation()
        for child in node.childNodes :
            if ( child.nodeName == "name" ) :
                newArgument.setName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "type" ) :
                newArgument.setTypeName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "const" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newArgument.setConstness( True )
            elif ( child.nodeName == "ref" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newArgument.setReference( True )
            elif ( child.nodeName == "ptr" ) :
                if ( not child.hasChildNodes() or \
                     child.firstChild.nodeValue.strip() == "true" ) :
                    newArgument.setPointer( True )
            elif ( child.nodeName == "default" ) :
                newArgument.setDefault( child.firstChild.nodeValue.strip() )

        return newArgument
    ## Reads and builds an instance of %TypeDefRepresentation from a
    ## &lt;typedef&gt; of &lt;globalTypedef&gt; element node.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] node element node defining the typedef.
    #
    # @return an instance of %TypeDefRepresentation.
    def readTypedef( self, node ) :
        newTypedef = TypeDefRepresentation()
        for child in node.childNodes :
            if ( child.nodeName == "aliasedType" ) :
                newTypedef.setName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "alias" ) :
                newTypedef.setAlias( child.firstChild.nodeValue.strip() )
        return newTypedef
    ## Reads and builds an instance of %EnumRepresentation from an
    ## &lt;enum&gt; or &lt;globalEnum&gt; element node.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] node element node defining the enum.
    #
    # @return an instance of %EnumRepresentation.
    def readEnum( self, node ) :
        newEnum = EnumRepresentation()
        name = ""
        value = ""
        for child in node.childNodes :
            if ( child.nodeName == "typeName" ) :
                newEnum.setName( child.firstChild.nodeValue.strip() )
            elif ( child.nodeName == "identifier" ) :
                name = ""
                value = ""
                for grandChild in child.childNodes :
                    if ( grandChild.nodeName == "name" ) :
                        name = grandChild.firstChild.nodeValue.strip()
                    elif ( grandChild.nodeName == "value" ) :
                        value = grandChild.firstChild.nodeValue.strip()
                newEnum.addIdentifier( name, value )

        return newEnum
    ## Writes the header file of the classes read from the XML file.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] outputDir output directory path.
    def writeHeaderFile( self, outputDir="./" ) :
        for index, classRep in enumerate( self.__Representations ) :

            headerFileName = outputDir + "/" + classRep.getObjectName()
            headerFileName += self.getHeaderExtension()

            HeaderFile = self._safeFileOpening( headerFileName )
            if ( HeaderFile == None ) :
                continue

            # ifndef preproc line :
            preproc = "#ifndef " + classRep.getObjectName().upper()
            preproc += self.getHeaderExtension().replace( ".", "_" ).upper() + "\n"
            HeaderFile.write( preproc )

            # define preproc line :
            preproc = "#define " + classRep.getObjectName().upper()
            preproc += self.getHeaderExtension().replace( ".", "_" ).upper() + "\n"
            HeaderFile.write( preproc + "\n" )

            # Add "created with" comment
            from XmlCppClassGenerator import getName, getVersion
            message = self.__Translator.getInformationMessage( "credits" )[ 0 ]
            HeaderFile.write( message.format( getName(), getVersion() ) + \
                                  "\n\n" )

            # user file includes
            templateLine = "#include \"{0}\"\n"

            message = self.__Translator.getInformationMessage( "processingInclude" )[ 0 ]
            locStr = self.__Translator.getInformationString( "local" )[ 0 ]
            fileStr = self.__Translator.getInformationString( "header" )[ 0 ]

            if ( len( classRep.getHeaderInclude( True ) ) > 0 ) :
                for include in classRep.getHeaderInclude( True ) :
                    self.verbose( message.format( locStr, include, fileStr ) )
                    HeaderFile.write( templateLine.format( include ) )

                HeaderFile.write( "\n" )

            # system file includes
            templateLine = "#include <{0}>\n"

            locStr = self.__Translator.getInformationString( "system" )[ 0 ]

            if ( len( classRep.getHeaderInclude( False ) ) > 0 ) :
                for include in classRep.getHeaderInclude( False ) :
                    self.verbose( message.format( locStr, include, fileStr ) )
                    HeaderFile.write( templateLine.format( include ) )

                HeaderFile.write( "\n" )

            # using namespace lines
            templateLine = "using namespace {};\n"

            if ( len( classRep.getUsingNamespace( True ) ) > 0 ) :
                for using in classRep.getUsingNamespace( True ) :
                    HeaderFile.write( templateLine.format( using ) )

                HeaderFile.write( "\n" )

            # typedef line
            if ( len( classRep.getGlobalTypedef() ) > 0 ) :
                for typedef in classRep.getGlobalTypedef() :
                    if ( self.__FlagComment[ index ] ) :
                        HeaderFile.write( typedef.produceComment() )
                    HeaderFile.write( typedef.producePrototype() )

                HeaderFile.write( "\n" )

            # enum lines
            if ( len( classRep.getGlobalEnum() ) > 0 ) :
                for enum in classRep.getGlobalEnum() :
                    if ( self.__FlagComment[ index ] ) :
                        HeaderFile.write( enum.produceComment() )
                    HeaderFile.write( enum.producePrototype() )
                
                HeaderFile.write( "\n" )

            # forward declarations
            if ( len( classRep.getForwardDeclaration() ) > 0 ) :
                for forward in classRep.getForwardDeclaration() :
                    HeaderFile.write( forward + ";\n" )

                HeaderFile.write( "\n" )

            classRep.writeHeader( HeaderFile, self.__FlagComment[ index ] )

            # endif preproc line :
            preproc = "\n\n#endif // " + classRep.getObjectName().upper()
            preproc += self.getHeaderExtension().replace( ".", "_" ).upper() + "\n"
            HeaderFile.write( preproc )

            HeaderFile.close()
    ## Writes the implementation file of the classes read from the XML
    # file.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] outputDir output directory path.
    def writeImplementationFile( self, outputDir="./" ) :
        for classRep in self.__Representations :

            if ( classRep.isTemplate() ) :
                message = \
                    self.__Translator.getInformationMessage( "templateOutput" )[0]
                what = \
                    self.__Translator.getInformationString( classRep.getObjectType() )[0]
                self.info( message.format( classRep.getObjectName(), what ) )
                return

            implementationFileName = outputDir + "/" + classRep.getObjectName()
            implementationFileName += self.getImplementationExtension()

            ImplementationFile = self._safeFileOpening( implementationFileName )
            if ( ImplementationFile == None ) :
                continue

            # Add "created with" comment
            from XmlCppClassGenerator import getName, getVersion
            message = self.__Translator.getInformationMessage( "credits" )[ 0 ]
            ImplementationFile.write( message.format( getName(), \
                                                          getVersion() ) + \
                                  "\n\n" )
            
            ImplementationFile.write( "#include \"" + classRep.getObjectName() + self.getHeaderExtension() + "\"\n\n" )

            # user file includes
            templateLine = "#include \"{}\"\n"

            message = self.__Translator.getInformationMessage( "processingInclude" )[ 0 ]
            locStr = self.__Translator.getInformationString( "local" )[ 0 ]
            fileStr = self.__Translator.getInformationString( "implementation" )[ 0 ]

            if ( len( classRep.getImplementationInclude( True ) ) > 0 ) :
                for include in classRep.getImplementationInclude( True ) :
                    self.verbose( message.format( locStr, include, fileStr ) )
                    ImplementationFile.write( templateLine.format( include ) )

                ImplementationFile.write( "\n" )

            # system file includes
            templateLine = "#include <{}>\n"

            locStr = self.__Translator.getInformationString( "system" )[ 0 ]

            if ( len( classRep.getImplementationInclude( False ) ) > 0 ) :
                for include in classRep.getImplementationInclude( False ) :
                    self.verbose( message.format( locStr, include, fileStr ) )
                    ImplementationFile.write( templateLine.format( include ) )

                ImplementationFile.write( "\n" )

            # using namespace lines
            templateLine = "using namespace {};\n"

            if ( len( classRep.getUsingNamespace( False ) ) > 0 ) :
                for using in classRep.getUsingNamespace( False ) :
                    ImplementationFile.write( templateLine.format( using ) )

                ImplementationFile.write( "\n" )

            classRep.writeImplementation( ImplementationFile )
        
            ImplementationFile.close()
    ## Checks whether a file exists. If yes, the present file is saved
    # to a ".BAK" file and the new one is opened.
    #
    # @param[in] self reference on the calling instance.
    # @param[in] fileName name of the file which will be opened.
    #
    # @return the opened file.
    def _safeFileOpening( self, fileName ) :
        if ( os.path.exists( fileName ) ) :
            message = self.__Translator.getInformationMessage( "objExist" )[0]
            self.verbose( message.format( fileName ) )
            if ( os.path.isfile( fileName ) ) :
                message = \
                    self.__Translator.getInformationMessage( "objIsFile" )[0]
                self.verbose( message.format( fileName ) )
                message = \
                    self.__Translator.getInformationMessage( "moveInfo" )[0]
                self.info( message.format( fileName ) )
                command = [ "mv", fileName, fileName + ".BAK" ]
                subprocess.call( command )
            else :
                message = \
                    self.__Translator.getInformationMessage( "objIsOther" )[0]
                self.error( message.format( fileName ) )
                return None

        try :
            File = open( fileName, "w" )
        except IOError, ( errno, strerror ) :
            print fileName
            message = self.__Translator.getInformationMessage( "ioError" )[0]
            self.error( message.format( errno, strerror ) )
            return None

        return File
        
